﻿/*----------------------------------------------------
 * Author : Tharinduni Udugamasuriya
 * Date : 04th August 2014
 * StringValue, StringEnum : To handle Enum Values
 ---------------------------------------------------*/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace DSPL.Contracts.Common
{
     #region ENum Classes

        #region StringValue Class

        public class StringValue : System.Attribute
        {
            private string _value;

            public StringValue(string value)
            {
                _value = value;
            }

            public string Value
            {
                get { return _value; }
            }

        }

        #endregion

        #region StringEnum Class

        public static class StringEnum
        {
            public static string GetStringValue(Enum value)
            {
                string output = null;
                Type type = value.GetType();

                FieldInfo fi = type.GetField(value.ToString());
                StringValue[] attrs =
                   fi.GetCustomAttributes(typeof(StringValue),
                                           false) as StringValue[];
                if (attrs.Length > 0)
                {
                    output = attrs[0].Value;
                }

                return output;
            }
        }
        #endregion


        #endregion

}
